﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace _51_AOP.Utility.Filter
{
    public class CustomAsyncResultFilterAttribute : Attribute, IAsyncResultFilter
    {
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {

            Console.WriteLine("视图执行之前");
            if (context.Result is JsonResult)
            {
                JsonResult jsonResult = (JsonResult)context.Result;
                context.Result = new JsonResult(new Models.AjaxResult()
                {
                    Success = true,
                    Message = "ok",
                    Data = jsonResult.Value
                });
            }
            ResultExecutedContext executedContext = await next.Invoke(); //执行委托
            

            Console.WriteLine("视图执行之后");
        }
    }
}
